package com.itheima.controller;

import com.itheima.pojo.AddressBook;
import com.itheima.pojo.Result;
import com.itheima.service.impl.AddressBookServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Log4j2
@RestController
@RequestMapping("/addressBook")
// TODO: 2022/10/20 收货人地址模块 订单列表模块 优化 
public class AddressBookController {

    @Autowired
    private AddressBookServiceImpl addressBookService;

    /**
     * 添加收货地址
     * @param addressBook
     * @return
     */
    @PostMapping
    public Result add( @RequestBody AddressBook addressBook){
    return addressBookService.add(addressBook);
    }

    /**
     * 获取收货地址列表
     */
    @GetMapping("/list")
    public Result getlist(){
        return addressBookService.getlist();
    }

    /**
     * 修改收货地址
     */
    @PutMapping
    public Result put(@RequestBody AddressBook addressBook){
        return addressBookService.put(addressBook);
    }

    /**
     * 收货地址根据id查询
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id){
        return addressBookService.chaeckById(id);
    }

    /**
     * 设置默认收货地址
     */
    @PutMapping("/default")
    public Result setUpDefault(@RequestBody AddressBook addressBook){
        return addressBookService.setUpDefault(addressBook);
    }

    /**
     * 获取默认地址
     */
    @GetMapping("/default")
    public Result getDefault(){
        return addressBookService.getDefault();
    }

    /**
     * 删除收货地址
     */
    @DeleteMapping
    public Result delete(String ids){
    return addressBookService.delect(ids);
    }

}
